package com.edu.kindergarten.ui;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;

import com.edu.kindergarten.R;
import com.edu.kindergarten.adapter.SuggestionListAdapter;
import com.edu.kindergarten.entity.SuggestionEntity;
import com.edu.kindergarten.utils.LogUtils;
import com.edu.kindergarten.utils.UiUtils;

public class SuggestionDetailActivity extends BaseActivity{ 
	private static final String TAG = "SuggestionDetailActivity";
	private final int REQUEST_PUBLISH_SUGGESTION_DATA = 100;
	private BaseAdapter mAdapter;
	private ImageView imgBtn;
	private List<SuggestionEntity> entityList = new ArrayList<SuggestionEntity>();
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_suggestion_detail);
		LogUtils.d(TAG,"onCreate");
		
		imgBtn = (ImageView)findViewById(R.id.answer_suggestion);
		imgBtn.setOnClickListener(new View.OnClickListener(){
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				startActivity(new Intent(SuggestionDetailActivity.this, AnswerSuggestionActivity.class));
			}		
		});
		//initData();
		//initView();
	}
	
	private void initData(){

		//dummy data
		SuggestionEntity entity1 = new SuggestionEntity();
		int drawableId1 = R.drawable.personal_arrow;;
		entity1.setStatus_img(drawableId1);
		entity1.setStatus_text("ÒÑ·´À¡");
		entity1.setTheme("·¹ÌÃ»ïÊ³±È½Ï²î");
		entity1.setDate("[2015/01/24]");
		entity1.setContent("È«¹úÕþÐ­³£Î¯¡¢Ãñ×åºÍ×Ú½ÌÎ¯Ô±»áÖ÷ÈÎÖìÎ¬Èº±íÊ¾£¬×î½ü¼¸Äê£¬´ïÀµÀ®ÂïÔÚ¹ú¼ÊÉÏ´®·Ã£¬°Ý¼ûËûµÄÈËÔ½À´Ô½ÉÙ...");
		entityList.add(entity1);
		
		SuggestionEntity entity2 = new SuggestionEntity();
		int drawableId2 = R.drawable.personal_arrow;
		entity2.setStatus_img(drawableId2);
		entity2.setStatus_text("µÈ´ý·´À¡");
		entity2.setTheme("Æ»¹û·¢²¼»á");
		entity2.setDate("[2015/01/22]");
		entity2.setContent("Æ»¹û·¢²¼»áÀúÀ´±»Ó÷Îª¡°¿Æ¼¼´ºÍí¡±£¬ÔÚ¸Õ½áÊøµÄ·¢²¼»áÉÏ£¬³ýÁË±¸ÊÜÖõÄ¿µÄApple WatchÍâ£¬12´çMacbookµÄÁÁÏàÒ²³ÉÎª¹Ø×¢½¹µã£¬ÕâÊÇÆ»¹û±Ê¼Ç±¾µçÄÔ²úÆ·...");
		entityList.add(entity2);
	}
	
	public void initView(){
		
		ListView listView = (ListView)findViewById(R.id.list_view);
		mAdapter = new SuggestionListAdapter(this, R.layout.layout_item_suggestion, entityList, 
							                 new int[]{R.id.status_img,
													   R.id.status_text,
													   R.id.theme,
													   R.id.date,
													   R.id.content});
		listView.setAdapter(mAdapter);
		
		imgBtn = (ImageView)findViewById(R.id.publish_suggestion);
		imgBtn.setOnClickListener(new View.OnClickListener(){
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				startActivityForResult(new Intent(SuggestionDetailActivity.this, PublishSuggestionActivity.class),
						REQUEST_PUBLISH_SUGGESTION_DATA);
			}		
		});
	}
	
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(resultCode != RESULT_OK){
			return;
		}
		switch(requestCode){
			case 100:
				SuggestionEntity suggestionEntity = new SuggestionEntity();
				
				int drawableId = R.drawable.personal_arrow;
				suggestionEntity.setStatus_img(drawableId);
				suggestionEntity.setStatus_text("µÈ´ý·´À¡");
				suggestionEntity.setTheme(data.getStringExtra("THEME"));
				suggestionEntity.setDate(data.getStringExtra("DATE"));
				suggestionEntity.setContent(data.getStringExtra("CONTENT"));
				suggestionEntity.setImgPaths(data.getStringArrayListExtra("IMG_PATH"));
				
				entityList.add(suggestionEntity);
				mAdapter.notifyDataSetChanged();
				
				break;
			default:
				break;
		}
		
	}


	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		LogUtils.d(TAG,"onDestroy");
		if (entityList != null) {
			entityList.clear();
		}
	}

	@Override
	public void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		LogUtils.d(TAG,"onPause");
	}

	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		LogUtils.d(TAG,"onResume");
	}

	@Override
	public void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		LogUtils.d(TAG,"onStart");
	}

	@Override
	public void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		LogUtils.d(TAG,"onStop");
	}
	
	
}
